class Player
  
  attr_accessor :camera_control, :pawn
  
  def initialize(controlled_object)
    @camera_speed = 3
    @pawn = controlled_object
    $game.player = self
    $game.camera.follows_object @pawn
  end
  
  def button_down(id)
    #puts id
    if not @pawn then
      return nil
    end
    
    if @pawn.is_a? Vehicle then
      if id == Controls[:select_weapongroup_1] then
        @pawn.select_weapon_group 1
      end
      if id == Controls[:select_weapongroup_2] then
        @pawn.select_weapon_group 2
      end
      if id == Controls[:select_weapongroup_3] then
        @pawn.select_weapon_group 3
      end
      
    elsif @pawn.is_a? Menu
      if id == Controls[:menu_down] then
        @pawn.select_next
      end
      if id == Controls[:menu_up] then
        @pawn.select_prev
      end
      if id == Controls[:menu_select] then
        @pawn.select
      end
      
    end
    
  end
    
  def update
    if not @pawn then 
      return nil
    end
    
    if @pawn.is_a? Camera
      
      if $game.button_down? Controls[:camera_down] then
        @pawn.down @camera_speed
      end

      if $game.button_down? Controls[:camera_up] then
        @pawn.up @camera_speed
      end

      if $game.button_down? Controls[:camera_right] then
        @pawn.right @camera_speed
      end

      if $game.button_down? Controls[:camera_left] then
        @pawn.left @camera_speed
      end
    elsif @pawn.is_a? Vehicle
      # player controls
      
      #if $game.button_down? $game.char_to_button_id(?a) then
      #  puts 'omg'
      #end
      #puts $game.button_down? Gosu::KbA
      
      if $game.button_down? Controls[:fire] then
        @pawn.fire
      end
      
      if $game.button_down? Controls[:fire_group_1] then
        @pawn.fire_group 1
      end
      
      if $game.button_down? Controls[:fire_group_2] then
        @pawn.fire_group 2
      end
      
      if $game.button_down? Controls[:fire_group_3] then
        puts 'lol'
        @pawn.fire_group 3
      end
      
      
      if $game.button_down? Controls[:accel] then
        @pawn.accelerate
      end
    
      if $game.button_down? Controls[:reverse] then
        @pawn.reverse
      end
  
      if $game.button_down? Controls[:turn_right] then
        @pawn.turn_right
      end
  
      if $game.button_down? Controls[:turn_left] then
        @pawn.turn_left
      end
    end
  end
    
  
end